package com.wusong.services;

public class GoldMsg {

	// 消息读取时间
	public String msgTime;

	// 中间价
	public String midPrice;

	// 买入价
	public String salePrice;

	// 卖出价
	public String buyPrice;

	// 美元价
	public String dollarPrice;

	// 美元 指数
	public String dollarIndex;

	// 原油指数
	public String oilIndex;

	public String getFormatString() {

		return "时间:" + this.msgTime + ",买入价:" + this.buyPrice + ",卖出价:"
				+ this.salePrice + ",中间价:" + this.midPrice + ",美元金:"
				+ this.dollarPrice + ",美元指数" + this.dollarIndex + ",原油指数:"
				+ this.oilIndex;

	}

	// time=16:02:11&gold=|321.31|320.96|321.66|322.24|320.98|1570.82|82.39|79.13
	public static GoldMsg valueOf(String textValue) {

		GoldMsg msg = new GoldMsg();
		if (textValue != null && textValue.length() > 10) {
			String[] timeAndValue = textValue.split("&");
			String time = timeAndValue[0];
			String[] timeArr = time.split("=");
			String[] valueArr = timeAndValue[1].split("\\|");

			msg.msgTime = timeArr[1];
			msg.midPrice = valueArr[1];
			msg.salePrice = valueArr[2];
			msg.buyPrice = valueArr[3];
			msg.dollarPrice = valueArr[6];
			msg.dollarIndex = valueArr[7];
			msg.oilIndex = valueArr[8];
		}
		return msg;
	}
}
